<?php

class AtomFeedBean extends Databean {

    public function addEntry($entry) {
        if (!is_a($entry,'AtomEntryBean'))
            return false;

        if ($entry->updated->isAfter($this->updated)) {
            $this->updated=$entry->updated;
        }
        $key=$entry->published->torfc3339().$entry->id; // echo "<p>$key</p>";
        $this->entries[$key]=$entry;
        krsort($this->entries);
        // echo '<pre>'; print_r($entries);
        return true;
    }

<<<<<<< .mine
=======
    /**
     * generate the XML feed
     * @return string
     */
    public function generateXml() {
        $xml='<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title type="text">'.$this->title.'</title>';
        if ($this->subtitle)
            $xml.='<subtitle type="{{ subtitle.type }}">{{ subtitle.content }}</subtitle>';

        $xml.='<updated>'.$this->updated->torfc3339().'</updated>'
        .'<id>'.$this->id.'</id>';
        if ($this->self)
            $xml.='<link rel="self" href="'.$this->self.'" />';
        foreach ($this->entries as $e) {
            $xml.='<entry>
            <title>'.$e->title.'</title>';
            if ($e->link)
                $xml.='<link rel="alternate" type="text/html"
                href="'.$e->link.'"/>';
            $xml.='<id>'.$this->id.'/'.$e->id.'</id>
            <updated>'.$e->updated->torfc3339().'</updated>';
            if ($e->published)
                $xml.='<published>'.$e->published->torfc3339().'</published>';
            if ($e->author)
                $xml.='<author>
                <name>'.$e->author.'</name>
            </author>';
            /*{% for c in e.contributors %}<contributor>
                <name>{{ c.name }}</name>
            </contributor>{% endfor %}*/
            if ($e->summary)
                $xml.='<summary>'.$e->summary.'</summary>';
            /*{% if e.content %}<content type="xhtml" xml:lang="{{ e.lang }}"
                xml:base="{{ e.base }}">
                {% comment %}content must be wrapped into div !{% endcomment %}
                <div xmlns="http://www.w3.org/1999/xhtml">
                    {{ e.content }}
                </div>
            </content>{% endif %}*/
            $xml.='</entry>';
        }
        $xml.='</feed>';
        return $xml;
    }

>>>>>>> .r471
    /**
     * @var string
     */
    public $id;
    protected function _id_required() {
        return true;
    }

    /**
     * @var string
     */
    public $title;
    protected function _title_required() {
        return true;
    }

    public $subtitle;

    /**
     * @var DateTimeBean
     */
    public $updated;
    protected function _updated_required() {
        return true;
    }
    protected function _updated_inputFilter($x) {
        return $this->_toDateTimeBean($x);
    }
    protected function _updated_autoValue() {
        return new DateTimeBean('1900-01-01');
    }
    
    /**
     * @var string self url
     */
    public $self;

    /**
     * @var array AtomEntry elements ordered by updated desc
     */
    public $entries=array();

    /**
    * value to datetimebean
    * @param mixed $value
    * @access private
    * @return datetimebean
    */
    function & _toDateTimeBean($value) {
        if (class_exists('datetimebean') and !is_null($value) and $value)
            $value=&new datetimebean($value);
        return $value;
    }/**/
}
